Glasgow | 25 SDC NOV | Katarzyna Kazimierczuk | Sprint 2 | Lru cache#118
Open
katarzynakaz wants to merge 2 commits intoCodeYourFuture:mainfrom
Open
Glasgow | 25 SDC NOV | Katarzyna Kazimierczuk | Sprint 2 | Lru cache#118katarzynakaz wants to merge 2 commits intoCodeYourFuture:mainfrom
katarzynakaz wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
reviewed
Feb 26, 2026
cjyuan
left a comment
There was a problem hiding this comment.
Can you implement the LruCache as a class?
Comment on lines
+59
to
+101
| #before i did it this was but was looping over each item and did not | ||
| #fit the required complexity | ||
| # def get_old(key): | ||
| # for item in our_list: | ||
| # if item["key"] == key: | ||
| # item["tracker"] = time.time() | ||
| # our_list.remove(item) | ||
| # our_list.insert(0, item) | ||
| # return item["value"] | ||
| # return None | ||
|
|
||
| #and before tried with an id not timestamp | ||
| # tracker_number = 0 | ||
|
|
||
| # def set(key, value): | ||
| # global tracker_number, our_list, lookup_map | ||
|
|
||
|
|
||
| # wrapped_item = { | ||
| # "key": key, | ||
| # "value": value, | ||
| # "tracker": tracker_number | ||
| # } | ||
|
|
||
|
|
||
| # tracker_number += 1 | ||
|
|
||
| # our_list.insert(0, wrapped_item) | ||
| # lookup_map[key] = wrapped_item | ||
|
|
||
| # and the loop | ||
| # def get_old(key): | ||
| # global tracker_number, our_list | ||
| # for item in our_list: | ||
| # if item["key"] == key: | ||
| # item["tracker"] = tracker_number | ||
| # tracker_number += 1 | ||
|
|
||
| # our_list.remove(item) | ||
| # our_list.insert(0, item) | ||
|
|
||
| # return item["value"] | ||
| # return None No newline at end of file |
There was a problem hiding this comment.
If this code are not used, can you remove them to keep the code clean?
Comment on lines
+3
to
+4
| our_list = [] | ||
| lookup_map = {} |
There was a problem hiding this comment.
OrderedDict is probably more efficient.
| wrapped_item = { | ||
| "key": key, | ||
| "value": value, | ||
| "tracker": time.time() |
There was a problem hiding this comment.
Is the value of property tracker used anywhere in your implementation to determine the order of the item? Do you need this property?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Self checklist
Changelist
Sprint 2 lru cache task is implemented.